package com.ostrich.a2104shopping.ui.home;

import com.ostrich.a2104shopping.ui.home.entity.AddCarRequestEntity;
import com.ostrich.a2104shopping.ui.home.entity.CarEntity;
import com.ostrich.a2104shopping.ui.home.entity.CategoryEntity;
import com.ostrich.a2104shopping.ui.home.entity.GoodsDetailEntity;
import com.ostrich.a2104shopping.ui.home.entity.GoodsEntity;
import com.ostrich.a2104shopping.ui.home.entity.IdsRequestEntity;
import com.ostrich.a2104shopping.ui.home.room.AppDataBase;
import com.ostrich.a2104shopping.ui.home.room.GoodsDao;
import com.ostrich.lib_common.net.BaseResponseEntity;
import com.ostrich.lib_common.net.RetrofitManager;

import java.util.List;

import androidx.lifecycle.LiveData;
import androidx.room.Insert;
import retrofit2.http.Body;
import retrofit2.http.Query;

/**
 * @Author : yaotianxue
 * @Time : On 2023/10/6 09:03
 * @Description : HomeRepository
 */
public class HomeRepository {
    private HomeApi mHomeApi;
    private GoodsDao mGoodsDao;

    public HomeRepository() {
        mHomeApi = RetrofitManager.getInstance().getRetrofit().create(HomeApi.class);
        mGoodsDao = AppDataBase.getInstance().getGoodsDao();
    }

    public LiveData<BaseResponseEntity<List<CategoryEntity>>> category(){
        return mHomeApi.category();
    }

    public LiveData<BaseResponseEntity<List<GoodsEntity>>> info(int category_id,int currentPage, int pageSize){
        return mHomeApi.info(category_id,currentPage,pageSize);
    }

    public LiveData<BaseResponseEntity<GoodsDetailEntity>> detail( int goods_id){
        return mHomeApi.detail(goods_id);
    }

    public LiveData<BaseResponseEntity> addCar( AddCarRequestEntity requestEntity){
        return mHomeApi.addCar(requestEntity);
    }

    public LiveData<BaseResponseEntity<List<CarEntity>>> selectCar(){
        return mHomeApi.selectCar();
    }
    public  LiveData<BaseResponseEntity<String>> deleteCar( IdsRequestEntity requestEntity){
        return mHomeApi.deleteCar(requestEntity);
    }


    public void insertAll(List<GoodsEntity> list){
        mGoodsDao.insertAll(list);
    }


    public List<GoodsEntity>  select(String keywords){
        return mGoodsDao.select(keywords);
    }


}
